local skel = fk.CreateSkill {
  name = "emo__yuxiang",
}

skel:addEffect(fk.CardUseFinished, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.card:isVirtual() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = #data.card.subcards
    local prompt = "#emo__yuxiang-invoke1::"..target.id
    if n ~= 1 then prompt = "#emo__yuxiang-invoke::"..target.id..":"..n end
    if room:askToSkillInvoke(player, {skill_name = skel.name, prompt = prompt}) then
      local choice = "draw"
      if n ~= 1 then
        choice = room:askToChoice(player, {skill_name = skel.name, choices =
        {"#emo__yuxiang-draw:::" .. n,  "#emo__yuxiang-discard:::" .. n}})
      end
      event:setCostData(self, {tos = {target}, choice = choice})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = target
    local n = #data.card.subcards
    local choice = event:getCostData(self).choice
    if string.find(choice, "draw") then
      if n > 0 then
        to:drawCards(n, skel.name)
      end
      room:askToDiscard(to, {min_num = 1, max_num = 1, skill_name = skel.name, include_equip = true, cancelable = false})
    else
      to:drawCards(1, skel.name)
      if n > 0 then
        room:askToDiscard(to, {min_num = n, max_num = n, skill_name = skel.name, include_equip = true, cancelable = false})
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__yuxiang"] = "余响",
  [":emo__yuxiang"] = "当一名角色使用转化或虚拟牌后，你可以选一项令其执行：<br>①：摸1张牌并弃X张牌；<br>②：摸X张牌并弃1张牌；<br>(X为此牌所含的实体牌数)",
  ["#emo__yuxiang-invoke"] = "余响：可令 %dest 摸一张牌再弃%arg张牌；或摸%arg张牌再弃一张牌",
  ["#emo__yuxiang-invoke1"] = "余响：可令 %dest 摸一张牌再弃一张牌",
  ["@@emo__yuxiang_target-turn"] = "余响",
  ["#emo__yuxiang-draw"] = "摸%arg张牌，弃1张牌",
  ["#emo__yuxiang-discard"] = "摸1张牌，弃%arg张牌",
}

return skel
